﻿
@{
    //Layout = "~/Views/Shared/_LayoutAdmin.cshtml"; ;
    Layout = null;
}

<script src="http://maps.google.com/maps/api/js?sensor=true" type="text/javascript"></script>
<script type="text/javascript">
    var markers = eval('@Html.Raw(ViewBag.Markers)');
   
    window.onload = function () {
        var mapOptions = {
            center: new google.maps.LatLng(markers[0].GeoLong, markers[0].GeoLat),
            zoom: 15,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var infoWindow = new google.maps.InfoWindow();
        var map = new google.maps.Map(document.getElementById("dvMap"), mapOptions);
        for (i = 0; i < markers.length; i++) {
            var data = markers[i]
            var myLatlng = new google.maps.LatLng(data.GeoLong, data.GeoLat);
            
            var marker = new google.maps.Marker({
                position: myLatlng,
                map: map,
                title: data.DisplayName,
                icon: "/images/icons/" + data.Status + ".png"
            });

            console.log("MAP", data, myLatlng, marker);
            (function (marker, data) {
                google.maps.event.addListener(marker, "click", function (e) {
                    infoWindow.setContent("<strong>" + data.DisplayName + "</strong>" + "<br/>" + data.Address);
                    infoWindow.open(map, marker);
                });
            })(marker, data);
        }
    }
</script>

<div id="dvMap" class="gmaps">
</div>